package logic

import (
	"an_ju_ke/myrpc/myrpcclient"
	"context"

	"an_ju_ke/myapi/internal/svc"
	"an_ju_ke/myapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ImageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageLogic {
	return &ImageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ImageLogic) Image(req *types.ImageRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	image, err := l.svcCtx.UserRpc.Image(l.ctx, &myrpcclient.ImageRequest{
		UserName: req.Name,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "获取成功",
		Data:    image,
	}, nil
}
